package com.bss.model;

import java.util.LinkedHashSet;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Transient;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;

@Entity
@Table(name = "patient")
public class Patient extends Person {

	private static final long serialVersionUID = 6921782931551918740L;

	private String firstName;

	private String middleName;

	private String lastName;

	private String addressLine1;

	private String addressLine2;

	private State state = new State();

	private Country country = new Country();

	private Place place = new Place();

	private String pin;

	private Religion religion = new Religion();

	private String phone;

	private Set<Attendent> attendents = new LinkedHashSet<Attendent>(0);

	private Set<Admission> admissions = new LinkedHashSet<Admission>(0);

	@NotNull(message = "{patient.firstName.NotNull}")
	@Size(min = 1, max = 45, message = "{patient.firstName.Size}")
	@Column(name = "firstName", nullable = false, length = 45)
	public String getFirstName() {
		return this.firstName;
	}

	public void setFirstName(final String firstName) {
		this.firstName = firstName;
	}

	@Size(max = 45, message = "{patient.middleName.Size}")
	@Column(name = "middleName", length = 45)
	public String getMiddleName() {
		return this.middleName;
	}

	public void setMiddleName(final String middleName) {
		this.middleName = middleName;
	}

	@NotNull(message = "{patient.lastName.NotNull}")
	@Size(min = 1, max = 45, message = "{patient.lastName.Size}")
	@Column(name = "lastName", nullable = false, length = 45)
	public String getLastName() {
		return this.lastName;
	}

	public void setLastName(final String lastName) {
		this.lastName = lastName;
	}

	@NotNull(message = "{patient.phone.NotNull}")
	@Size(min = 1, max = 20, message = "{patient.phone.Size}")
	@Column(name = "phone", length = 20)
	public String getPhone() {
		return this.phone;
	}

	public void setPhone(final String phone) {
		this.phone = phone;
	}

	@OneToMany(fetch = FetchType.LAZY, mappedBy = "patient")
	public Set<Attendent> getAttendents() {
		return this.attendents;
	}

	public void setAttendents(final Set<Attendent> attendents) {
		this.attendents = attendents;
	}

	@OneToMany(fetch = FetchType.LAZY, mappedBy = "patient")
	public Set<Admission> getAdmissions() {
		return this.admissions;
	}

	public void setAdmissions(final Set<Admission> admissions) {
		this.admissions = admissions;
	}

	@Transient
	public String getName() {
		// TODO Auto-generated method stub
		return this.getFirstName() + " " + this.getMiddleName() + " " + this.getLastName();
	}

	@Override
	public String toString() {
		// TODO
		return "Name: " + this.getName() + ", Address: " + ", Sex: " + this.getSex() + ", " + this.getProfession() + ", Phone:"
				+ this.getPhone();

	}

	@NotNull(message = "{patient.addressLine1.NotNull}")
	@Size(min = 1, max = 100, message = "{patient.addressLine1.Size}")
	public String getAddressLine1() {
		return this.addressLine1;
	}

	public void setAddressLine1(String addressLine1) {
		this.addressLine1 = addressLine1;
	}

	@Size(max = 100, message = "{patient.addressLine2.Size}")
	public String getAddressLine2() {
		return this.addressLine2;
	}

	public void setAddressLine2(String addressLine2) {
		this.addressLine2 = addressLine2;
	}

	@NotNull(message = "{patient.state.NotNull}")
	@ManyToOne(fetch = FetchType.EAGER)
	@JoinColumn(name = "idState")
	public State getState() {
		return this.state;
	}

	public void setState(State state) {
		this.state = state;
	}

	@NotNull(message = "{patient.country.NotNull}")
	@ManyToOne(fetch = FetchType.EAGER)
	@JoinColumn(name = "idCountry")
	public Country getCountry() {
		return this.country;
	}

	public void setCountry(Country country) {
		this.country = country;
	}

	@NotNull(message = "{patient.place.NotNull}")
	@ManyToOne(fetch = FetchType.EAGER)
	@JoinColumn(name = "idPlace")
	public Place getPlace() {
		return this.place;
	}

	public void setPlace(Place place) {
		this.place = place;
	}

	@NotNull(message = "{patient.religion.NotNull}")
	@ManyToOne(fetch = FetchType.EAGER)
	@JoinColumn(name = "idReligion")
	public Religion getReligion() {
		return this.religion;
	}

	public void setReligion(Religion religion) {
		this.religion = religion;
	}

	@NotNull(message = "{patient.pin.NotNull}")
	@Size(min = 1, max = 6, message = "{patient.pin.Size}")
	public String getPin() {
		return this.pin;
	}

	public void setPin(String pin) {
		this.pin = pin;
	}

	// @Override
	// @NotNull(message = "{patient.photo.NotNull}")
	// public byte[] getPhoto() {
	// return super.getPhoto();
	// }
}
